/**
 * Created by hcadmin on 16/3/1.
 */

define([
    "jquery",
    "IO",
    "bootbox"
], function($,IO,bootbox) {
    $(function () {
        var grid;
        //每列数据列性
        var columns = [
            {
                title: '资讯',
                dataIndex: 'title',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span><img src='" + data[datarow].cover + "' width='80px;' height='80px;'>&nbsp;&nbsp;</span>" + data[datarow].title + "</span>";
                }
            },
            {
                title: '发布时间',
                dataIndex: 'create_date',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].create_date + "</span>";
                }
            },
            {
                title: '资讯分类',
                dataIndex: 'category_name',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].category_name + "</span>";
                }
            },
            {
                title: '点赞数',
                dataIndex: 'upvote_num',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].upvote_num + "</span>";
                }
            },
            {
                title: '操作',
                dataIndex: 'action',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span><a href='javascript:void(0)' style='color: red;' class='delete' act_id='"+data[datarow].information_id+"'>删除</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='/pte/update_inform?information_id="+data[datarow].information_id+"' style='color: orange;'>编辑</a></span>";
                }
            },

        ];


        //数组初始化

        function dataInit() {
            grid = new Grid("/pte/api/inform", $("#table_my_toast"), $("#paging_my_toast"), 1, 10, columns, get_input_param(), 10);

            //初始化
            grid.Init();
        }

        //获取输入框内容
        function get_input_param() {
            var category_id=$("#info_category option:selected").attr("data-id");
            var param="category_id= " + category_id;
            console.log(category_id);
            return param;
        }
        dataInit();
        //查询
        $("#searchid").bind("click", function () {
            dataInit();
        });
    });
    //删除课程
    $(document).on("click",".delete",function(){
        var act_id=$(this).attr("act_id");
        if(act_id){
            bootbox.confirm("确定要删除该课程？",function(result){
                if(result) {
                    IO.get("act/info_delete",{act_id:act_id},function(d){
                        bootbox.alert(d.msg,function(){
                            if (d.code == 0) {
                                location.href = '/pte/informlb';
                            }
                        })
                    });
                }
            });
        }
    });

});
